<?php

namespace App\Http\Controllers\Home;

use App\Services\Home\ArticleService;
use App\Services\Home\RegionService;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class ArticleController extends Controller
{

    protected $service;
    protected $regionService;

    public function __construct(ArticleService $service,RegionService $regionService)
    {
        $this->service = $service;
        $this->regionService = $regionService;
    }

    public function index($city)
    {
        //资讯
        $data = $this->service->getArticleList($city);
        $info = $this->getInfo($city);
        $city_info = $info['city_info'];
        $hot_rec = $info['hot_rec'];
        $hand_rec = $info['hand_rec'];
        return view('home.article_list',compact('data','city_info','hot_rec','hand_rec'));
    }

    public function show($city,$id)
    {
        $data = $this->service->getArticleDetail($id);
        $info = $this->getInfo($city);
        $city_info = $info['city_info'];
        $hot_rec = $info['hot_rec'];
        $hand_rec = $info['hand_rec'];
        return view('home.article',compact('data','city_info','hot_rec','hand_rec'));
    }

    private function getInfo($city)
    {
        //所属城市
        $data['city_info'] = $this->regionService->getCityInfo($city);
        // 热门楼盘
        $data['hot_rec'] = $this->service->getHotProperty($city);
        // 推荐二手房
        $data['hand_rec'] = $this->service->getRecHandRoom($city);
        return $data;
    }
}
